package com.itcast.googleplay.fragment;

import com.itcast.googleplay.ui.LoadingPage;
import com.itcast.googleplay.ui.LoadingPage.ResultState;
import com.itcast.googleplay.utils.UIUtils;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public abstract class BaseFragment extends Fragment {
	private LoadingPage loadingPage;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		loadingPage = new LoadingPage(UIUtils.getContext()) {

			@Override
			public ResultState onLoad() {
				//请求网络的方法,此方法必须返回一个请求结果(成功,失败,为空)
				//因为BaseFragmet是七个子类模块的父类,7个界面请求网络方式未知(url),无法实现所以抽象
				return onSubLoad();
			}

			@Override
			public View onCreateSuccessedView() {
				//加载成功构建成功view的方法
				//因为BaseFragmet是七个子类模块的父类,7个子类模块的页面效果全部不同,所以成功的view无法做具体的实现,所以抽象
				return onCreateSubSuccessedView();
			}
		};
		//loadingPage就是个帧布局,在此帧布局中添加了四种类型的界面(成功,失败,为空,加载中),已经通过网络请求状态,决定了那个界面显示那个界面隐藏
		return loadingPage;
	}
	
	public abstract ResultState onSubLoad();
	public abstract View onCreateSubSuccessedView();
	
	//提供一个请求网络的触发点
	public void subShow(){
		if(loadingPage!=null){
			loadingPage.show();
		}
	}
}
